-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added JSON Save and Load #166
base: master
Are you sure you want to change the base?
Conversation
I only really did that for completeness (and absentmindedly I thought it might be nice to be able to paste JSON somewhere else and edit it). The actual calls and default parameters for those functions are such that the operation is still carried out in pickle. Happy to remove those extra lines, that's a simple change. Edit: I'll just take the initiative and remove it. |
…utput JSON; modified regex for stripping out time codes to match changes.
I added a line in app.py to intend the JSON so it's human readable, and also to sort the tags. Sorting the tags makes the regex in the storypanel.py stripTimeFields method more rebust. However, using this regex to strip out the time information is a hack I would rather do without. The trouble is: the JSON is too messy with the time codes left in, but the time codes have to stay in the pickling of the class, otherwise the original file format won't be backwards comparable. |
Line 324 of tiddlywiki.py states that pickling has been broken for older versions of Twine. However there is a contradicting note on Line 341 about maintaining compatibility with Twine 1.3.5. If compatibility is no longer a requirement, the attributes 'created' and 'modified' could be removed from getstate, which would in turn remove the need to strip these attributes out when saving JSON. |
I thought it would be useful for Twine to be able to save and load JSON instead of pickle dumps. I wrote some changes to use the jsonpickle library instead of pickle. You can now "Save as JSON..." and this will save a .twjs file. Open now loads both the original .tws files and the JSON .twjs files. I use a regex in StoryPanel to remove the time fields from the jsonpickled classes. This is because I see they are being phased out, and there is no general way to remove them from the get/setstate methods which will work with legacy files.